home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / accounts / acct-1.3 / acct-1 / acct-1.3.73 / kernel_diffs-1.3.71 < prev    next >
Text File  |  1996-03-04  |  11KB  |  345 lines

  1. diff -ru --new-file linux/arch/alpha/kernel/signal.c linux-1.3.71/arch/alpha/kernel/signal.c
  2. --- linux/arch/alpha/kernel/signal.c    Sat Feb 17 09:19:38 1996
  3. +++ linux-1.3.71/arch/alpha/kernel/signal.c    Mon Mar  4 13:48:36 1996
  4. @@ -283,6 +283,7 @@
  5.                  /* fall through */
  6.              default:
  7.                  current->signal |= _S(signr & 0x7f);
  8. +                current->flags |= PF_SIGNALED;
  9.                  do_exit(signr);
  10.              }
  11.          }
  12. diff -ru --new-file linux/arch/i386/kernel/signal.c linux-1.3.71/arch/i386/kernel/signal.c
  13. --- linux/arch/i386/kernel/signal.c    Sat Feb 17 08:07:01 1996
  14. +++ linux-1.3.71/arch/i386/kernel/signal.c    Mon Mar  4 13:48:36 1996
  15. @@ -215,6 +215,7 @@
  16.                  /* fall through */
  17.              default:
  18.                  current->signal |= _S(signr & 0x7f);
  19. +                current->flags |= PF_SIGNALED;
  20.                  do_exit(signr);
  21.              }
  22.          }
  23. diff -ru --new-file linux/arch/mips/kernel/signal.c linux-1.3.71/arch/mips/kernel/signal.c
  24. --- linux/arch/mips/kernel/signal.c    Wed Dec 13 12:39:44 1995
  25. +++ linux-1.3.71/arch/mips/kernel/signal.c    Mon Mar  4 13:48:36 1996
  26. @@ -302,6 +302,7 @@
  27.                  /* fall through */
  28.              default:
  29.                  current->signal |= _S(signr & 0x7f);
  30. +                current->flags |= PF_SIGNALED;
  31.                  do_exit(signr);
  32.              }
  33.          }
  34. diff -ru --new-file linux/arch/ppc/kernel/signal.c linux-1.3.71/arch/ppc/kernel/signal.c
  35. --- linux/arch/ppc/kernel/signal.c    Sat Dec 30 15:48:22 1995
  36. +++ linux-1.3.71/arch/ppc/kernel/signal.c    Mon Mar  4 13:48:36 1996
  37. @@ -166,6 +166,7 @@
  38.                  /* fall through */
  39.              default:
  40.                  current->signal |= _S(signr & 0x7f);
  41. +                current->flags |= PF_SIGNALED;
  42.                  do_exit(signr);
  43.              }
  44.          }
  45. diff -ru --new-file linux/arch/sparc/kernel/signal.c linux-1.3.71/arch/sparc/kernel/signal.c
  46. --- linux/arch/sparc/kernel/signal.c    Mon Mar  4 08:49:56 1996
  47. +++ linux-1.3.71/arch/sparc/kernel/signal.c    Mon Mar  4 13:48:36 1996
  48. @@ -260,6 +260,7 @@
  49.                  /* fall through */
  50.              default:
  51.                  current->signal |= _S(signr & 0x7f);
  52. +                current->flags |= PF_SIGNALED;
  53.                  do_exit(signr);
  54.              }
  55.          }
  56. diff -ru --new-file linux/fs/binfmt_aout.c linux-1.3.71/fs/binfmt_aout.c
  57. --- linux/fs/binfmt_aout.c    Sat Mar  2 20:29:23 1996
  58. +++ linux-1.3.71/fs/binfmt_aout.c    Mon Mar  4 13:48:36 1996
  59. @@ -129,6 +129,7 @@
  60.      if (!file.f_op->write)
  61.          goto close_coredump;
  62.      has_dumped = 1;
  63. +    current->flags |= PF_DUMPCORE;
  64.             strncpy(dump.u_comm, current->comm, sizeof(current->comm));
  65.      dump.u_ar0 = (void *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump)));
  66.      dump.signal = signr;
  67. @@ -313,6 +314,7 @@
  68.      current->mm->mmap = NULL;
  69.      current->suid = current->euid = current->fsuid = bprm->e_uid;
  70.      current->sgid = current->egid = current->fsgid = bprm->e_gid;
  71. +     current->flags &= ~PF_FORKNOEXEC;
  72.      if (N_MAGIC(ex) == OMAGIC) {
  73.  #ifdef __alpha__
  74.          do_mmap(NULL, N_TXTADDR(ex) & PAGE_MASK,
  75. diff -ru --new-file linux/fs/binfmt_elf.c linux-1.3.71/fs/binfmt_elf.c
  76. --- linux/fs/binfmt_elf.c    Sat Mar  2 20:29:23 1996
  77. +++ linux-1.3.71/fs/binfmt_elf.c    Mon Mar  4 13:51:55 1996
  78. @@ -624,6 +624,7 @@
  79.  #endif
  80.      current->suid = current->euid = current->fsuid = bprm->e_uid;
  81.      current->sgid = current->egid = current->fsgid = bprm->e_gid;
  82. +    current->flags &= ~PF_FORKNOEXEC;
  83.      bprm->p = (unsigned long) 
  84.        create_elf_tables((char *)bprm->p,
  85.              bprm->argc,
  86. @@ -1020,6 +1021,7 @@
  87.      if (!file.f_op->write)
  88.          goto close_coredump;
  89.      has_dumped = 1;
  90. +    current->flags |= PF_DUMPCORE;
  91.  
  92.      DUMP_WRITE(&elf, sizeof(elf));
  93.      offset += sizeof(elf);                /* Elf header */
  94. diff -ru --new-file linux/include/linux/acct.h linux-1.3.71/include/linux/acct.h
  95. --- linux/include/linux/acct.h    Thu Jan  1 02:00:00 1970
  96. +++ linux-1.3.71/include/linux/acct.h    Mon Mar  4 13:48:36 1996
  97. @@ -0,0 +1,29 @@
  98. +#ifndef __LINUX_ACCT_H
  99. +#define __LINUX_ACCT_H
  100. +
  101. +#define ACCT_COMM 16
  102. +
  103. +struct acct
  104. +{
  105. +    char    ac_comm[ACCT_COMM];    /* Accounting command name */
  106. +    time_t    ac_utime;        /* Accounting user time */
  107. +    time_t    ac_stime;        /* Accounting system time */
  108. +    time_t    ac_etime;        /* Accounting elapsed time */
  109. +    time_t    ac_btime;        /* Beginning time */
  110. +    uid_t    ac_uid;            /* Accounting user ID */
  111. +    gid_t    ac_gid;            /* Accounting group ID */
  112. +    dev_t    ac_tty;            /* controlling tty */
  113. +    char    ac_flag;        /* Accounting flag */
  114. +    long    ac_minflt;        /* Accounting minor pagefaults */
  115. +    long    ac_majflt;        /* Accounting major pagefaults */
  116. +    long    ac_exitcode;        /* Accounting process exitcode */
  117. +};
  118. +
  119. +#define AFORK    0001    /* has executed fork, but no exec */
  120. +#define ASU    0002    /* used super-user privileges */
  121. +#define ACORE    0004    /* dumped core */
  122. +#define AXSIG    0010    /* killed by a signal */
  123. +
  124. +#define AHZ     100
  125. +
  126. +#endif
  127. diff -ru --new-file linux/include/linux/kernel.h linux-1.3.71/include/linux/kernel.h
  128. --- linux/include/linux/kernel.h    Thu Feb 22 15:51:08 1996
  129. +++ linux-1.3.71/include/linux/kernel.h    Mon Mar  4 13:48:36 1996
  130. @@ -58,16 +58,9 @@
  131.      __attribute__ ((format (printf, 1, 2)));
  132.  
  133.  /*
  134. - * This is defined as a macro, but at some point this might become a
  135. - * real subroutine that sets a flag if it returns true (to do
  136. - * BSD-style accounting where the process is flagged if it uses root
  137. - * privs).  The implication of this is that you should do normal
  138. - * permissions checks first, and check suser() last.
  139. - *
  140.   * "suser()" checks against the effective user id, while "fsuser()"
  141.   * is used for file permission checking and checks against the fsuid..
  142.   */
  143. -#define suser() (current->euid == 0)
  144.  #define fsuser() (current->fsuid == 0)
  145.  
  146.  #endif /* __KERNEL__ */
  147. diff -ru --new-file linux/include/linux/sched.h linux-1.3.71/include/linux/sched.h
  148. --- linux/include/linux/sched.h    Mon Mar  4 10:24:39 1996
  149. +++ linux-1.3.71/include/linux/sched.h    Mon Mar  4 13:48:37 1996
  150. @@ -259,6 +259,10 @@
  151.                      /* Not implemented yet, only for 486*/
  152.  #define PF_PTRACED    0x00000010    /* set if ptrace (0) has been called. */
  153.  #define PF_TRACESYS    0x00000020    /* tracing system calls */
  154. +#define PF_FORKNOEXEC    0x00000040    /* forked but didn't exec */
  155. +#define PF_SUPERPREV    0x00000100    /* used super-user privileges */
  156. +#define PF_DUMPCORE    0x00000200    /* dumped core */
  157. +#define PF_SIGNALED    0x00000400    /* killed by a signal */
  158.  
  159.  #define PF_STARTING    0x00000100    /* being created */
  160.  #define PF_EXITING    0x00000200    /* getting shut down */
  161. @@ -348,6 +352,19 @@
  162.                 const char *device,
  163.                 void *dev_id);
  164.  extern void free_irq(unsigned int irq, void *dev_id);
  165. +
  166. +/*
  167. + * This has now become a routine instead of a macro, it sets a flag if
  168. + * it returns true (to do BSD-style accounting where the process is flagged
  169. + * if it uses root privs). The implication of this is that you should do
  170. + * normal permissions checks first, and check suser() last.
  171. + */
  172. +extern inline int suser(void)
  173. +{
  174. +    if (current->euid == 0)
  175. +        current->flags |= PF_SUPERPREV;
  176. +    return (current->euid == 0);
  177. +}
  178.  
  179.  extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
  180.  extern void flush_thread(void);
  181. diff -ru --new-file linux/kernel/exit.c linux-1.3.71/kernel/exit.c
  182. --- linux/kernel/exit.c    Sat Feb 17 09:19:43 1996
  183. +++ linux-1.3.71/kernel/exit.c    Mon Mar  4 13:48:37 1996
  184. @@ -18,6 +18,7 @@
  185.  
  186.  #include <asm/segment.h>
  187.  extern void sem_exit (void);
  188. +extern void acct_process (long exitcode);
  189.  extern void kerneld_exit(void);
  190.  
  191.  int getrusage(struct task_struct *, int, struct rusage *);
  192. @@ -509,6 +510,7 @@
  193.          intr_count = 0;
  194.      }
  195.  fake_volatile:
  196. +    acct_process(code);
  197.      current->flags |= PF_EXITING;
  198.      del_timer(¤t->real_timer);
  199.      sem_exit();
  200. diff -ru --new-file linux/kernel/fork.c linux-1.3.71/kernel/fork.c
  201. --- linux/kernel/fork.c    Fri Dec 15 12:48:37 1995
  202. +++ linux-1.3.71/kernel/fork.c    Mon Mar  4 13:48:37 1996
  203. @@ -226,7 +226,8 @@
  204.      p->kernel_stack_page = new_stack;
  205.      *(unsigned long *) p->kernel_stack_page = STACK_MAGIC;
  206.      p->state = TASK_UNINTERRUPTIBLE;
  207. -    p->flags &= ~(PF_PTRACED|PF_TRACESYS);
  208. +    p->flags &= ~(PF_PTRACED|PF_TRACESYS|PF_SUPERPREV);
  209. +    p->flags |= PF_FORKNOEXEC;
  210.      p->pid = get_pid(clone_flags);
  211.      p->next_run = NULL;
  212.      p->prev_run = NULL;
  213. diff -ru --new-file linux/kernel/sys.c linux-1.3.71/kernel/sys.c
  214. --- linux/kernel/sys.c    Fri Mar  1 08:18:12 1996
  215. +++ linux-1.3.71/kernel/sys.c    Mon Mar  4 13:48:37 1996
  216. @@ -19,6 +19,10 @@
  217.  #include <linux/mm.h>
  218.  #include <linux/pagemap.h>
  219.  #include <linux/swap.h>
  220. +#include <linux/fcntl.h>
  221. +#include <linux/acct.h>
  222. +#include <linux/tty.h>
  223. +#include <sys/sysmacros.h>
  224.  
  225.  #include <asm/segment.h>
  226.  #include <asm/io.h>
  227. @@ -272,10 +276,113 @@
  228.          current->dumpable = 0;
  229.      return 0;
  230.  }
  231. -
  232. -asmlinkage int sys_acct(void)
  233. -{
  234. -    return -ENOSYS;
  235. +  
  236. +static char acct_active = 0;
  237. +static struct file acct_file;
  238. +
  239. +int acct_process(long exitcode)
  240. +{
  241. +   struct acct ac;
  242. +   unsigned short fs;
  243. +
  244. +   if (acct_active) {
  245. +      strncpy(ac.ac_comm, current->comm, ACCT_COMM);
  246. +      ac.ac_comm[ACCT_COMM] = '\0';
  247. +      ac.ac_utime = current->utime;
  248. +      ac.ac_stime = current->stime;
  249. +      ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ));
  250. +      ac.ac_etime = CURRENT_TIME - ac.ac_btime;
  251. +      ac.ac_uid   = current->uid;
  252. +      ac.ac_gid   = current->gid;
  253. +      ac.ac_tty   = (current)->tty == NULL ? -1 : 
  254. +         makedev (4, current->tty->device);
  255. +      ac.ac_flag  = 0;
  256. +      if (current->flags & PF_FORKNOEXEC)
  257. +         ac.ac_flag |= AFORK;
  258. +      if (current->flags & PF_SUPERPREV)
  259. +         ac.ac_flag |= ASU;
  260. +      if (current->flags & PF_DUMPCORE)
  261. +         ac.ac_flag |= ACORE;
  262. +      if (current->flags & PF_SIGNALED)
  263. +         ac.ac_flag |= AXSIG;
  264. +      ac.ac_minflt = current->min_flt;
  265. +      ac.ac_majflt = current->maj_flt;
  266. +      ac.ac_exitcode = exitcode;
  267. +
  268. +      /* Kernel segment override */
  269. +      fs = get_fs();
  270. +      set_fs(KERNEL_DS);
  271. +
  272. +      acct_file.f_op->write(acct_file.f_inode, &acct_file,
  273. +                             (char *)&ac, sizeof(struct acct));
  274. +
  275. +      set_fs(fs);
  276. +   }
  277. +   return 0;
  278. +}
  279. +
  280. +asmlinkage int sys_acct(const char *name)
  281. +{
  282. +   struct inode *inode = (struct inode *)0;
  283. +   char *tmp;
  284. +   int error;
  285. +
  286. +   if (!suser())
  287. +      return -EPERM;
  288. +
  289. +   if (name == (char *)0) {
  290. +      if (acct_active) {
  291. +         if (acct_file.f_op->release)
  292. +            acct_file.f_op->release(acct_file.f_inode, &acct_file);
  293. +
  294. +         if (acct_file.f_inode != (struct inode *) 0)
  295. +            iput(acct_file.f_inode);
  296. +
  297. +         acct_active = 0;
  298. +      }
  299. +      return 0;
  300. +   } else {
  301. +      if (!acct_active) {
  302. +
  303. +         if ((error = getname(name, &tmp)) != 0)
  304. +            return (error);
  305. +
  306. +         error = open_namei(tmp, O_RDWR, 0600, &inode, 0);
  307. +         putname(tmp);
  308. +
  309. +         if (error)
  310. +            return (error);
  311. +
  312. +         if (!S_ISREG(inode->i_mode)) {
  313. +            iput(inode);
  314. +            return -EACCES;
  315. +         }
  316. +
  317. +         if (!inode->i_op || !inode->i_op->default_file_ops || 
  318. +             !inode->i_op->default_file_ops->write) {
  319. +            iput(inode);
  320. +            return -EIO;
  321. +         }
  322. +
  323. +         acct_file.f_mode = 3;
  324. +         acct_file.f_flags = 0;
  325. +         acct_file.f_count = 1;
  326. +         acct_file.f_inode = inode;
  327. +         acct_file.f_pos = inode->i_size;
  328. +         acct_file.f_reada = 0;
  329. +         acct_file.f_op = inode->i_op->default_file_ops;
  330. +
  331. +         if (acct_file.f_op->open)
  332. +            if (acct_file.f_op->open(acct_file.f_inode, &acct_file)) {
  333. +               iput(inode);
  334. +               return -EIO;
  335. +            }
  336. +
  337. +         acct_active = 1;
  338. +         return 0;
  339. +      } else
  340. +         return -EBUSY;
  341. +   }
  342.  }
  343.  
  344.  #ifndef __alpha__
  345.